import { Controller, Post, Body, UseGuards } from '@nestjs/common'
import { VerificationService } from './verification.service'
import { ApiBearerAuth, ApiConsumes, ApiOperation, ApiTags } from '@nestjs/swagger'
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'
import { SendEmailCodeDto, SendPhoneCodeDto } from '../user/dto/verify-code.dto'
import { RateLimit } from '../common/rateLimit/rate-limit.decorator'

@ApiTags('common')
@Controller('common')
// @UseGuards(JwtAuthGuard)
// @ApiBearerAuth('JWT')
export class VerificationController {
  constructor(private verificationService: VerificationService) { }
  // 发送邮箱验证码
  @ApiOperation({ summary: '发送邮箱验证码' })
  @ApiConsumes('application/x-www-form-urlencoded')
  @RateLimit(1, 60 * 1000)
  @Post('email/randCode')
  async sendEmailCode(@Body() data: SendEmailCodeDto) {
    return this.verificationService.sendEmailCode({ email: data.email })
  }

  // 发送手机验证码
  @ApiOperation({ summary: '发送手机验证码' })
  @ApiConsumes('application/x-www-form-urlencoded')
  @RateLimit(1, 60 * 1000)
  @Post('phone/randCode')
  async sendPhoneCode(@Body() data: SendPhoneCodeDto) {
    return this.verificationService.sendPhoneCode({ phone: data.phone })
  }
}